/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package to.pm.catalogo.core;

import java.util.List;
import javax.persistence.Query;
import javax.persistence.EntityManager;
import to.pm.entity.catalogo.Categoria;

/**
 *
 * @author sp043784
 */
public class GestioneCategorie {

    private EntityManager em;

    public void setEm(EntityManager em) {
        this.em = em;
    }

    public EntityManager getEm() {
        return em;
    }

   public List<Categoria> getCategorie(){
        Query createQuery = getEm().createQuery("select object(o) from Categoria as o");
        return createQuery.getResultList();
    }

   public void addCategoria(Categoria cat){
       //check
       //if is not root
       //   and is in the same type of categories of father node and...

       em.persist(cat);
   }

}
